<?php

namespace Modules\Shop\Http\Controllers;

use Illuminate\Support\Facades\Request;
use Modules\Shop\Service\CouponService;
use Modules\Shop\Http\Requests\Coupon\CouponRequest;


class CouponController extends BaseController
{   

    private $coupon_types = ['2'=>'满减券','3'=>'折扣券'];

	/**
     *  优惠券列表
     *  hinq 2019 08 21
     *
     **/
    public function index(){

        $arr_search = (array)Request::input();
        $arr_list = CouponService::get_list( (array) $arr_search );
        echo_error($arr_list);
        return view('shop::coupon.index',$arr_list['data']);
    }



    /**
     *	添加优惠券视图
     *	hinq 2019 08 22
     *
     **/
    public function create(){

        $shop_id = shop_user()['shop_id'];
        //如果当前登录的用户是维修店（其他角色不用获取），获取商品的分类，然后通过商品类型获取商品信息
        //可以设置某一分类下所有的商品， 也可指定某一些商品
        return view('shop::coupon.create' , ['coupons_types'=>$this->coupon_types , 'shop_id'=>$shop_id]);
    }


    /**
     *	添加优惠券数据
     *	hinq 2019 08 22
     *
     **/
    public function store(){
    	$arrInput = (array) Request::all();
    	return CouponService::add_one( (array) $arrInput );

    }

    /**
     *	编辑优惠券视图
     *	hinq 2019 08 22 
     *
     **/
    public function edit(){
    	$nId = (int)(int)Request::get('id',0);
    	$arr_info = CouponService::get_one( (int) $nId );
        return view('shop::coupon.edit',['info' => $arr_info ,'coupons_types'=>$this->coupon_types]);
    }


    /**
     *	编辑优惠券数据
     *	hinq 2019 08 22
     *
     **/
    public function update(){
    	$arrInput = (array) Request::all();
    	return CouponService::edit_one( (array) $arrInput );
    }



    /**
     *  优惠券使用、领取明细列表
     *  hinq 2019 08 29
     *
     **/
    public function list(){
        $arr_search = (array) Request::all();
        $arr_list = CouponService::get_list_to_use( (array) $arr_search );
        echo_error($arr_list);
        return view('shop::coupon.list',$arr_list['data']);
    }

    /**
     *  使用优惠券 搜索优惠券券号使用
     *  hinq  2019 09 06
     *
     **/
    public function coupon_use(){
        $nId = (int) Request::get('id');
        return CouponService::coupon_use( (int) $nId );
    }


    /**
     *  优惠券关联用户详情
     *  hinq 2019 09 17
     *
     **/
    public function list_extend(){
        $arr_search = (array) Request::all();
        $arr_list = CouponService::list_extend( (array) $arr_search );
        echo_error($arr_list);
        return view('shop::coupon.list_extend',$arr_list['data']);
    }

    /**
     *  商家按照优惠券号搜索优惠券详细信息  只能查找洗车券
     *  hinq 2020 3 14
     *
     **/
    public function search(){
        $arr_input = (array) Request::all();

        if( !empty( $arr_input['ticket_num'] ) ){
            $arr_list = CouponService::get_search_counpon( (array) $arr_input );
        }else{
            $arr_list['data'] = [];
        }
        return view('shop::coupon.search' , $arr_list['data']);
    }
}

